﻿using System;
using System.Windows;
using System.Windows.Controls;
//using SomethingSpacialClassLib.Web;
using SomethingSpacial.Web;
using SomethingSpacial.ViewModel;


namespace SomethingSpacial.Views.Admin
{
    public partial class LocationList : Page
    {

        SomethingSpacialContext domainContext = new SomethingSpacialContext();

        public LocationList()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(LocationList_Loaded);
        }

        #region "Page Events"

        void LocationList_Loaded(object sender, RoutedEventArgs e)
        {
            ((LocationsViewModel)this.DataContext).loadLocations();
        }


        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            editDataForm.CommitEdit();
            domainContext.SubmitChanges();
        }

        private void AddNew_Click(object sender, RoutedEventArgs e)
        {
            var w = new LocationAdd();
            w.Closed += addNewWindow_Closed;
            w.Show();
        }

        void addNewWindow_Closed(object sender, EventArgs e)
        {

            LocationAdd addForm = (LocationAdd)sender;
            if (addForm.NewLocation != null)
            {
                ((LocationsViewModel)this.DataContext).addLocation(addForm.NewLocation);
            }

        }

        #endregion





    }
}
